package com.tf.pemporaryfood.service.serviceImpl;

import com.tf.pemporaryfood.domain.entity.Category;
import com.tf.pemporaryfood.mapper.CategoryMapper;
import com.tf.pemporaryfood.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> findCategoriesAll() {
        //给实体类分类
        List<Category> categoryList = categoryMapper.findCategoryByLevel(0);
        List<Category> category2 = categoryMapper.findCategoryByLevel(1);
        for (Category c: categoryList) {
            c.setChildren(category2.stream().filter(c2 -> c2.getCatePid() == c.getCateId()).collect(Collectors.toList()));
        }
        return categoryList;
    }
}
